subroutine CalcSourceLocation(SourceLocation, iCellSource)
!use DataSource
use Data_Mesh, only: nCells, meshCellCenters
implicit none
    real(8),intent(in) :: SourceLocation(3)
    integer,intent(out) :: iCellSource
    
    integer :: iCell
    real(8) :: R, Rmin
    
    Rmin = sum((meshCellCenters(1:3,1)+SourceLocation(1:3))**2)
    iCellSource = 1
    do iCell = 2,nCells
        R = sum((meshCellCenters(1:3,iCell)+SourceLocation(1:3))**2)
        if(R.lt.Rmin)then
            Rmin = R
            iCellSource = iCell
        end if
    end do

end subroutine CalcSourceLocation

subroutine CalcSource(time,Q)
use DataSource
implicit none
    real(8),intent(in) :: time
    real(8),intent(out) :: Q

    real(8) :: Pi

    if(time.lt.SourceStartTime)then
        Q = 0d0
        return
    end if

    Pi = 3.1415926535897932384626433832795
!    Q = Amplitude * sin(2.0d0 * PeriodDiv2Pi * Pi * time)
    Q = Amplitude * cos(2.0d0 * PeriodDiv2Pi * Pi * time)

end subroutine CalcSource
